"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Type;
(function (Type) {
    Type[Type["Interval"] = 0] = "Interval";
    Type[Type["Timeout"] = 1] = "Timeout";
})(Type = exports.Type || (exports.Type = {}));
class Delayed {
    constructor(handler, args, time, type) {
        this.active = true;
        this.paused = false;
        this.elapsedTime = 0;
        this.handler = handler;
        this.args = args;
        this.time = time;
        this.type = type;
    }
    tick(deltaTime) {
        if (this.paused) {
            return;
        }
        this.elapsedTime += deltaTime;
        if (this.elapsedTime >= this.time) {
            this.execute();
        }
    }
    execute() {
        this.handler.apply(this, this.args);
        if (this.type === Type.Timeout) {
            this.active = false;
        }
        else {
            this.elapsedTime -= this.time;
        }
    }
    reset() {
        this.elapsedTime = 0;
    }
    pause() {
        this.paused = true;
    }
    resume() {
        this.paused = false;
    }
    clear() {
        this.active = false;
    }
}
exports.Delayed = Delayed;
